package org.dromara.crawler.config;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

/**
 * @author Shup
 * @date 2025/6/24 11:03
 */
@Converter(autoApply = true)
public class JSONObjectConverter implements AttributeConverter<JSONObject, String> {

    @Override
    public String convertToDatabaseColumn(JSONObject attribute) {
        return attribute != null ? attribute.toString() : null;
    }

    @Override
    public JSONObject convertToEntityAttribute(String dbData) {
        return dbData != null ? JSONUtil.parseObj(dbData) : null;
    }
}
